Ext.define('AmpleHarvest.objects.metrics.reports.cReport',
{
	extend			: 'Ext.panel.Panel',
	alias			: 'widget.ampleharvest-objects-metrics-reports-creport',
	title			: 'LOADING...',
	requires		:
	[
			'Ext.LoadMask'
	],
	uses			:
	[
	 		'AmpleHarvest.objects.metrics.util.cMetricsUtils'
	],
	anchor			: '100% 100%',
	layout			: 'anchor',
	listeners		:
	{
		loadData	: function(obj_data)
		{
			var obj_process = new Object();
			if(Ext.isArray(obj_data.data))
			{
				str_title = obj_data.data[0].title;
				obj_process = obj_data.data[0];
			} 
			else
			{
				str_title = obj_data.data.title;
				obj_process = obj_data.data;
			}
			this.setTitle(str_title);
			this.process_response(obj_process);
		}
	},	
	
	initComponent	: function()
	{
		this.util_metrics = Ext.create('AmpleHarvest.objects.metrics.util.cMetricsUtils');
		
		this.m_obj_Details = Ext.create("AmpleHarvest.objects.metrics.reports.objects.cDetails");

		this.m_obj_Toolbar = Ext.create('Ext.toolbar.Toolbar', 
				{
					alias : 'widget.ampleharvest-objects-metrics-reports-objects-ctoolbar'
				});
		
		this.items =
			[
			 	this.m_obj_Details
			 ];
		
		this.callParent();
		
		this.addDocked(this.m_obj_Toolbar, 'top');

		this.util_metrics.get_json({restPath	: this.m_str_id}, this);		
	},

	process_response	: function(obj_data)
	{
		var obj_info = new Object();
		obj_info.title = '';
		var str_seperator = ' ::+:: ';
		var x = 0;
		for (x in obj_data.titles.title)
		{
			if(x > 0)
			{
				obj_info.title += str_seperator;
			}
			obj_info.title += obj_data.titles.title[x];
		}
		this.m_obj_Details.obj_template.overwrite(this.m_obj_Details.body, obj_info);
		
		var str_href_parentSite = this.util_metrics.getLink('parentSite', obj_data['link-tree'].link);
		if(str_href_parentSite)
		{
			this.m_obj_btn_ParentSite = Ext.create('Ext.Button',
				{
					text	:'Parent Site',
					tooltip	: 'Go to parent site',
					handler	: function()
						{
							m_obj_AmpleHarvest_ViewPort.fireEvent(AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_METRICS_SITE_DETAIL,
									str_href_parentSite
							);
						}
				});
			this.m_obj_Toolbar.add(this.m_obj_btn_ParentSite);
		}
		
		this.util_metrics.createList(obj_data,
				{
					type	: 'threads',
					title	: 'Thread Metrics',
					anchor	: '99% 60%',
					columns: [
					          { header: 'Title', 					dataIndex: 'title', 				flex: 1 },
//					          { header: 'Posts', 					dataIndex: 'posts', 				flex: 1 },
					          { header: 'Avg Rate of change', 		dataIndex: 'postAvgRateOfChange', 	flex: 1 },
					          { header: 'Max Rate of change', 		dataIndex: 'postMaxRateOfChange', 	flex: 1 },
					          { header: 'Most Recent Delta', 		dataIndex: 'postMostRecentDelta', 	flex: 1 },
					          { header: 'Standard Deviation', 		dataIndex: 'postStandardDeviation', flex: 1 },
					          { header: 'Views', 					dataIndex: 'viewCount', 				flex: 1 },
					          { header: 'Avg Rate of change', 		dataIndex: 'viewAvgRateOfChange', 	flex: 1 },
					          { header: 'Max Rate of change', 		dataIndex: 'viewMaxRateOfChange', 	flex: 1 },
					          { header: 'Standard Deviation', 		dataIndex: 'viewStandardDeviation', flex: 1 }
					      ],
					tbar	: false,
					caller	: this,
					detail	: true,
					report	: false
				});
	}
}
);